#!/usr/bin/env tclsh

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# math_expression_fuzz_run failure with seed 1743159584
do_execsql_test fuzz-test-failure {
  SELECT mod(atanh(tanh(-1.0)), ((1.0))) / ((asinh(-1.0) / 2.0 * 1.0) + pow(0.0, 1.0) + 0.5);
} {-16.8596516555675}

do_execsql_test add-int-1 {
  SELECT 10 + 1
} {11}

do_execsql_test add-int-2 {
  SELECT 0xA + 0xFF
} {265}

do_execsql_test add-int-3 {
  SELECT 0xA + 1
} {11}


do_execsql_test add-float {
  SELECT 10.1 + 0.3
} {10.4}

do_execsql_test add-int-float-1 {
  SELECT 10 + 0.1
} {10.1}

do_execsql_test add-int-float-2 {
  SELECT 0xa + 0.1
} {10.1}

do_execsql_test add-agg-int-agg-int {
  SELECT sum(1) + sum(2)
} {3}

do_execsql_test add-agg-int-agg-float {
  SELECT sum(1) + sum(2.5)
} {3.5}

do_execsql_test add-agg-float-agg-int {
  SELECT sum(1.5) + sum(2)
} {3.5}

foreach {testnum lhs rhs ans} {
   1   'a'   'a'   0
   2   'a'   10    10
   3   10    'a'   10
   4   'a'   11.0  11.0
   5   11.0  'a'   11.0
   7   '1'   '2'   3
   8   '1.0' '2'   3.0
   9   '1.0' '3.0' 4.0
} {
  do_execsql_test add-text-$testnum "SELECT $lhs + $rhs" $::ans
}

foreach {testnum lhs rhs ans} {
   1   '9223372036854775807'   '0'   9223372036854775807
   2   '9223372036854775807'   '1'   9.22337203685478e+18
   3   9223372036854775807      0    9223372036854775807
   4   9223372036854775807      1    9.22337203685478e+18
   5   '-9223372036854775808'  '0'   -9223372036854775808
   6   '-9223372036854775808'  '-1'  -9.22337203685478e+18
   7   -9223372036854775808     0    -9223372036854775808
   8   -9223372036854775808     -1   -9.22337203685478e+18
} {
  do_execsql_test add-overflow-$testnum "SELECT $lhs + $rhs" $::ans
}

do_execsql_test subtract-int {
  SELECT 10 - 1
} {9}

do_execsql_test subtract-float {
  SELECT 10.2 - 0.1
} {10.1}

do_execsql_test subtract-int-float {
  SELECT 10 - 0.1
} {9.9}

do_execsql_test subtract-agg-int-agg-int {
  SELECT sum(3) - sum(1)
} {2}

do_execsql_test subtract-agg-int-agg-float {
  SELECT sum(3) - sum(1.5)
} {1.5}

do_execsql_test subtract-agg-float-agg-int {
  SELECT sum(3.5) - sum(1)
} {2.5}

do_execsql_test subtract-blob {
  SELECT -x'11'
} {0}

do_execsql_test subtract-blob-empty {
  SELECT -x''
} {0}

do_execsql_test subtract-blob-charcter {
  SELECT -'hi';
} {0}

foreach {testnum lhs rhs ans} {
   1   'a'   'a'   0
   2   'a'   10    -10
   3   10    'a'   10
   4   'a'   11.0  -11.0
   5   11.0  'a'   11.0
   7   '1'   '2'   -1
   8   '1.0' '2'   -1.0
   9   '1.0' '3.0' -2.0
} {
  do_execsql_test subtract-text-$testnum "SELECT $lhs - $rhs" $::ans
}

foreach {testnum lhs rhs ans} {
   1   '9223372036854775807'   '0'   9223372036854775807
   2   '9223372036854775807'   '-1'   9.22337203685478e+18
   3   9223372036854775807      0    9223372036854775807
   4   9223372036854775807      -1    9.22337203685478e+18
   5   '-9223372036854775808'  '0'   -9223372036854775808
   6   '-9223372036854775808'  '1'  -9.22337203685478e+18
   7   -9223372036854775808     0    -9223372036854775808
   8   -9223372036854775808     1   -9.22337203685478e+18
} {
  do_execsql_test subtract-overflow-$testnum "SELECT $lhs - $rhs" $::ans
}

do_execsql_test multiply-int {
  SELECT 10 * 2
} {20}

do_execsql_test multiply-float {
  SELECT 10.2 * 2.2
} {22.44}

do_execsql_test multiply-int-float {
  SELECT 10 * 1.45
} {14.5}

do_execsql_test multiply-float-int {
  SELECT 1.45 * 10
} {14.5}

do_execsql_test multiply-agg-int-agg-int {
  SELECT sum(2) * sum(3)
} {6}

do_execsql_test multiply-agg-int-agg-float {
  SELECT sum(2) * sum(3.5)
} {7.0}

do_execsql_test multiply-agg-float-agg-int {
  SELECT sum(2.5) * sum(3)
} {7.5}

foreach {testnum lhs rhs ans} {
   1   'a'   'a'   0
   2   'a'   10    0
   3   10    'a'   0
   4   'a'   11.0  0.0
   5   11.0  'a'   0.0
   7   '1'   '2'   2
   8   '1.0' '2'   2.0
   9   '1.0' '3.0' 3.0
} {
  do_execsql_test multiply-text-$testnum "SELECT $lhs * $rhs" $::ans
}

foreach {testnum lhs rhs ans} {
   1   '9223372036854775807'   '1'   9223372036854775807
   2   '9223372036854775807'   '2'   1.84467440737096e+19
   3   9223372036854775807      1    9223372036854775807
   4   9223372036854775807      2    1.84467440737096e+19
   5   '-9223372036854775808'  '1'   -9223372036854775808
   6   '-9223372036854775808'  '2'  -1.84467440737096e+19
   7   -9223372036854775808     1    -9223372036854775808
   8   -9223372036854775808     2   -1.84467440737096e+19
} {
  do_execsql_test multiply-overflow-$testnum "SELECT $lhs * $rhs" $::ans
}

do_execsql_test divide-int {
  SELECT 10 / 2
} {5}

do_execsql_test divide-int-no-fraction {
  SELECT 10 / 3
} {3}

do_execsql_test divide-float {
  SELECT 10.6 / 2.5
} {4.24}

do_execsql_test divide-int-float {
  SELECT 10 / 4.0
} {2.5}

do_execsql_test divide-float-int {
  SELECT 10.0 / 4
} {2.5}

do_execsql_test divide-by-zero {
  SELECT 10 / 0
} {}

do_execsql_test divide-int-null {
  SELECT 10 / null
} {}

do_execsql_test divide-null-int {
  SELECT null / 10
} {}

do_execsql_test divide-null {
  SELECT null / null
} {}

do_execsql_test divide-agg-int-agg-int {
  SELECT sum(4) / sum(2)
} {2}

do_execsql_test divide-agg-int-agg-float {
  SELECT sum(4) / sum(2.0)
} {2.0}

do_execsql_test divide-agg-float-agg-int {
  SELECT sum(4.0) / sum(2)
} {2.0}

foreach {testnum lhs rhs ans} {
   1   'a'   'a'   {}
   2   'a'   10    0
   3   10    'a'   {}
   4   'a'   11.0  0.0
   5   11.0  'a'   {}
   7   '1'   '2'   0
   8   '1.0' '2'   0.5
   9   '1.0' '4.0' 0.25
} {
  do_execsql_test divide-text-$testnum "SELECT $lhs / $rhs" $::ans
}

foreach {testnum lhs rhs ans} {
   5   '-9223372036854775808'  '0'   {}
   6   '-9223372036854775808'  '-1'  9.22337203685478e+18
   7   -9223372036854775808     0    {}
   8   -9223372036854775808     -1   9.22337203685478e+18
} {
  do_execsql_test divide-overflow-$testnum "SELECT $lhs / $rhs" $::ans
}

do_execsql_test add-agg-int {
  SELECT sum(id) + 10 from products
} {76}

do_execsql_test add-int-agg {
  SELECT 10 + sum(id) from products
} {76}

do_execsql_test add-agg-float {
  SELECT sum(id) + 10.1 from products
} {76.1}

do_execsql_test add-float-agg {
  SELECT 10.1 + sum(id) from products
} {76.1}

do_execsql_test add-agg-int-agg-int {
  SELECT sum(id) + sum(id) from products
} {132}

do_execsql_test add-agg-float-agg-float {
  SELECT sum(price) + sum(price) from products
} {1246.0}

do_execsql_test add-agg-int-agg-float {
  SELECT sum(id) + sum(price) from products
} {689.0}

do_execsql_test add-float-text-edgecase {
  SELECT '-123.22342-24' + '232.3x32';
} {109.07658}

do_execsql_test add-str-edgecase {
SELECT '-1+23.22342-24' + '2-32.3x32';
} {1}



do_execsql_test subtract-agg-int {
  SELECT sum(id) - 10 from products
} {56}

do_execsql_test subtract-int-agg {
  SELECT 10 - sum(id) from products
} {-56}

do_execsql_test subtract-agg-float {
  SELECT sum(id) - 10.1 from products
} {55.9}

do_execsql_test subtract-float-agg {
  SELECT 10.1 - sum(id) from products
} {-55.9}

do_execsql_test subtract-agg-int-agg-int {
  SELECT sum(id) - sum(id) from products
} {0}

do_execsql_test subtract-agg-float-agg-float {
  SELECT sum(price) - sum(price) from products
} {0.0}

do_execsql_test subtract-agg-int-agg-float {
  SELECT sum(id) - sum(price) from products
} {-557.0}

do_execsql_test subtract-agg-float-agg-int {
  SELECT sum(price) - sum(id) from products
} {557.0}

do_execsql_test subtract-str-float-edgecase {
  SELECT '-123.22342-24' - '232.3x32';
} {-355.52342}


do_execsql_test multiply-agg-int {
  SELECT sum(id) * 10 from products
} {660}

do_execsql_test multiply-int-agg {
  SELECT 10 * sum(id) from products
} {660}

do_execsql_test multiply-agg-float {
  SELECT sum(id) * 10.1 from products
} {666.6}

do_execsql_test multiply-float-agg {
  SELECT 10.1 * sum(id) from products
} {666.6}

do_execsql_test multiply-agg-int-agg-int {
  SELECT sum(id) * sum(id) from products
} {4356}

do_execsql_test multiply-agg-float-agg-float {
  SELECT sum(price) * sum(price) from products
} {388129.0}

do_execsql_test multiply-agg-int-agg-float {
  SELECT sum(id) * sum(price) from products
} {41118.0}

do_execsql_test multiply-agg-float-agg-int {
  SELECT sum(price) * sum(id) from products
} {41118.0}

do_execsql_test multiply-str-floats-edgecase {
  SELECT '-123.22341-24' * '232.3x32';
} {-28624.798143}


do_execsql_test divide-agg-int {
  SELECT sum(id) / 10 from products
} {6}

do_execsql_test divide-int-agg {
  SELECT 660 / sum(id) from products
} {10}

do_execsql_test divide-agg-float {
  SELECT sum(id) / 1.5 from products
} {44.0}

do_execsql_test divide-float-agg {
  SELECT 66.0 / sum(id) from products
} {1.0}

do_execsql_test divide-agg-int-agg-int {
  SELECT sum(id) / sum(id) from products
} {1}

do_execsql_test divide-agg-float-agg-float {
  SELECT sum(price) / sum(price) from products
} {1.0}

do_execsql_test divide-agg-int-agg-float {
  SELECT sum(id) / min(price) from products
} {66.0}

do_execsql_test divide-agg-float-agg-int {
  SELECT min(price) / min(id) from products
} {1.0}


do_execsql_test bitwise-and-int-null {
  SELECT 1234 & NULL
} {}

do_execsql_test bitwise-and-int-int {
  SELECT 1234 & 1234
} {1234}

do_execsql_test bitwise-and-int-float {
  SELECT 660 & 261.8
} {4}

do_execsql_test bitwise-and-float-float {
  SELECT 660.63 & 261.8
} {4}

do_execsql_test bitwise-and-float-int-rev {
  SELECT 261.8 & 660
} {4}

do_execsql_test bitwise-and-int-agg-int {
   SELECT 8261 & sum(id) from products
} {64}

do_execsql_test bitwise-and-int-agg-float {
    SELECT 1036.6 & sum(id) from products
} {0}

do_execsql_test bitwise-and-int-agg-int-agg {
    SELECT sum(id) & sum(id) from products
} {66}

foreach {testnum lhs rhs ans} {
   1   'a'   'a'   0
   2   'a'   10    0
   3   10    'a'   0
   4   'a'   11.0  0
   5   11.0  'a'   0
   7   '1'   '2'   0
   8   '1.0' '2'   0
   9   '1.0' '4.0' 0
   10  '1.0' '1.0' 1
   11  '1'   '1'   1
} {
  do_execsql_test bitwise-and-text-$testnum "SELECT $lhs & $rhs" $::ans
}


do_execsql_test bitwise-or-int-null {
    SELECT 1234 | NULL
} {}

do_execsql_test bitwise-or-null-int {
    SELECT NULL | 1234
} {}

do_execsql_test bitwise-or-int-int {
    SELECT 4321 | 1234
} {5363}

do_execsql_test bitwise-or-int-float {
    SELECT 660 | 1234.0
} {1750}

do_execsql_test bitwise-or-int-agg {
    SELECT 18823 | sum(id) from products
} {18887}

do_execsql_test bitwise-or-float-float {
    SELECT 1234.6 | 5432.2
} {5626}

foreach {testnum lhs rhs ans} {
   1   'a'   'a'   0
   2   'a'   10    10
   3   10    'a'   10
   4   'a'   11.0  11
   5   11.0  'a'   11
   7   '1'   '2'   3
   8   '1.0' '2'   3
   9   '1.0' '4.0' 5
   10  '1.0' '1.0' 1
   11  '1'   '1'   1
} {
  do_execsql_test bitwise-or-text-$testnum "SELECT $lhs | $rhs" $::ans
}

do_execsql_test bitwise-and-int-agg-int-agg {
    SELECT sum(id) | sum(id) from products
} {66}


foreach {testname lhs rhs ans} {
  int-int                 1     2       4
  int-neg_int             8     -2      2
  int-float               1     4.0     16
  int-text                1     'a'     1
  int-text_float          1     '3.0'   8
  int-text_int            1     '1'     2
  int-null                1     NULL    {}
  int-int-overflow        1     64      0
  int-int-underflow       1     -64     0
  int-float-overflow      1     64.0    0
  int-float-underflow     1     -64.0   0
} {
  do_execsql_test shift-left-$testname "SELECT $lhs << $rhs" $::ans
}

foreach {testname lhs rhs ans} {
  float-int               1.0     2       4
  float-neg_int           8.0     -2      2
  float-float             1.0     4.0     16
  float-text              1.0     'a'     1
  float-text_float        1.0     '3.0'   8
  float-text_int          1.0     '1'     2
  float-null              1.0     NULL    {}
  float-int-overflow      1.0     64      0
  float-int-underflow     1.0     -64     0
  float-float-overflow    1.0     64.0    0
  float-float-underflow   1.0     -64.0   0
} {
  do_execsql_test shift-left-$testname "SELECT $lhs << $rhs" $::ans
}

foreach {testname lhs rhs ans} {
   text-int                 'a'       2      0
   text-float               'a'       4.0    0
   text-text                'a'       'a'    0
   text_int-text_int        '1'       '1'    2
   text_int-text_float      '1'       '3.0'  8
   text_int-text            '1'       'a'    1
   text_float-text_int      '1.0'     '1'    2
   text_float-text_float    '1.0'     '3.0'  8
   text_float-text          '1.0'     'a'    1
   text-null                '1'       NULL   {}
} {
  do_execsql_test shift-left-$testname "SELECT $lhs << $rhs" $::ans
}

foreach {testname lhs rhs ans} {
   null-int         NULL       2      {}
   null-float       NULL       4.0    {}
   null-text        NULL       'a'    {}
   null-null        NULL       NULL   {}
} {
  do_execsql_test shift-left-$testname "SELECT $lhs << $rhs" $::ans
}

foreach {testname lhs rhs ans} {
  int-int                 8     2       2
  int-neg_int             8     -2      32
  int-float               8     1.0     4
  int-text                8     'a'     8
  int-text_float          8     '3.0'   1
  int-text_int            8     '1'     4
  int-null                8     NULL    {}
  int-int-overflow        8     64      0
  int-int-underflow       8     -64     0
  int-float-overflow      8     64.0    0
  int-float-underflow     8     -64.0   0
} {
  do_execsql_test shift-right-$testname "SELECT $lhs >> $rhs" $::ans
}

foreach {testname lhs rhs ans} {
  float-int               8.0     2       2
  float-neg_int           8.0     -2      32
  float-float             8.0     1.0     4
  float-text              8.0     'a'     8
  float-text_float        8.0     '3.0'   1
  float-text_int          8.0     '1'     4
  float-null              8.0     NULL    {}
  float-int-overflow      8.0     64      0
  float-int-underflow     8.0     -64     0
  float-float-overflow    8.0     64.0    0
  float-float-underflow   8.0     -64.0   0
} {
  do_execsql_test shift-right-$testname "SELECT $lhs >> $rhs" $::ans
}

foreach {testname lhs rhs ans} {
   text-int                 'a'       2      0
   text-float               'a'       4.0    0
   text-text                'a'       'a'    0
   text_int-text_int        '8'       '1'    4
   text_int-text_float      '8'       '3.0'  1
   text_int-text            '8'       'a'    8
   text_float-text_int      '8.0'     '1'    4
   text_float-text_float    '8.0'     '3.0'  1
   text_float-text          '8.0'     'a'    8
   text-int-text-edge       '123-23'  2      30
   text-signed-text-edge    '-123'    '2xi' -31
   text-null                '8'       NULL   {}
} {
  do_execsql_test shift-right-$testname "SELECT $lhs >> $rhs" $::ans
}

foreach {testname lhs rhs ans} {
   null-int         NULL       2      {}
   null-float       NULL       4.0    {}
   null-text        NULL       'a'    {}
   null-null        NULL       NULL   {}
} {
  do_execsql_test shift-right-$testname "SELECT $lhs >> $rhs" $::ans
}

do_execsql_test bitwise-not-null {
	SELECT ~NULL
} {}

do_execsql_test bitwise-not-int {
	SELECT ~1234
} {-1235}

do_execsql_test bitwise-not-float {
	SELECT ~823.34
} {-824}

do_execsql_test bitwise-not-text-float {
	SELECT ~'823.34'
} {-824}

do_execsql_test bitwise-not-text-int-1 {
	SELECT ~'1234'
} {-1235}

do_execsql_test bitwise-not-text-int-2 {
	SELECT ~0xA
} {-11}

do_execsql_test bitwise-not-scalar-float {
	SELECT ~abs(693.9)
} {-694}

do_execsql_test bitwise-not-scalar-int {
	SELECT ~abs(7566)
} {-7567}

do_execsql_test bitwise-not-agg-int {
	SELECT ~sum(693)
} {-694}

do_execsql_test bitwise-not-agg-and-agg {
	SELECT ~sum(693) & sum(-302)
} {-958}

do_execsql_test bitwise-not-agg-int {
	SELECT ~sum(693)
} {-694}

do_execsql_test bitwise-not-zero {
	SELECT ~0
} {-1}

do_execsql_test bitwise-not-empty-blob {
	SELECT ~x''
} {-1}

do_execsql_test bitwise-not-cast-blob {
	SELECT ~ CAST ('af' AS BLOB);
} {-1}

do_execsql_test bitwise-not-blob {
	SELECT ~ x'0000';
} {-1}

do_execsql_test bitwise-not-blob-2 {
	SELECT ~ x'0001';
} {-1}


do_execsql_test pi {
  SELECT pi()
} {3.14159265358979}


do_execsql_test acos-int {
  SELECT acos(1)
} {0.0}

do_execsql_test acos-float {
  SELECT acos(-0.5)
} {2.0943951023932}

do_execsql_test acos-str {
  SELECT acos('-0.5')
} {2.0943951023932}

do_execsql_test acos-null {
  SELECT acos(null)
} {}


do_execsql_test acosh-int {
  SELECT acosh(1)
} {0.0}

do_execsql_test acosh-float {
  SELECT acosh(1.5)
} {0.962423650119207}

do_execsql_test acosh-str {
  SELECT acosh('1.5')
} {0.962423650119207}

do_execsql_test acosh-invalid {
  SELECT acosh(0.99)
} {}

do_execsql_test acosh-null {
  SELECT acosh(null)
} {}


do_execsql_test asin-int {
  SELECT asin(1)
} {1.5707963267949}

do_execsql_test asin-float {
  SELECT asin(-0.5)
} {-0.523598775598299}

do_execsql_test asin-str {
  SELECT asin('-0.5')
} {-0.523598775598299}

do_execsql_test asin-null {
  SELECT asin(null)
} {}


do_execsql_test sin-int {
  SELECT sin(1)
} {0.841470984807897}

do_execsql_test sin-float {
  SELECT sin(-0.5)
} {-0.479425538604203}

do_execsql_test sin-str {
  SELECT sin('-0.5')
} {-0.479425538604203}

do_execsql_test sin-null {
  SELECT sin(null)
} {}

do_execsql_test sin-products-id {
  SELECT sin(id) from products limit 5
} {0.841470984807897
0.909297426825682
0.141120008059867
-0.756802495307928
-0.958924274663138}


do_execsql_test asinh-int {
  SELECT asinh(1)
} {0.881373587019543}

do_execsql_test asinh-float {
  SELECT asinh(-0.5)
} {-0.481211825059603}

do_execsql_test asinh-str {
  SELECT asinh('-0.5')
} {-0.481211825059603}

do_execsql_test asinh-null {
  SELECT asinh(null)
} {}


do_execsql_test atan-int {
  SELECT atan(1)
} {0.785398163397448}

do_execsql_test atan-float {
  SELECT atan(-0.5)
} {-0.463647609000806}

do_execsql_test atan-str {
  SELECT atan('-0.5')
} {-0.463647609000806}

do_execsql_test atan-null {
  SELECT atan(null)
} {}


do_execsql_test tan-int {
  SELECT tan(1)
} {1.5574077246549}

do_execsql_test tan-float {
  SELECT tan(-0.5)
} {-0.54630248984379}

do_execsql_test tan-str {
  SELECT tan('-0.5')
} {-0.54630248984379}

do_execsql_test tan-null {
  SELECT tan(null)
} {}


do_execsql_test atanh-int {
  SELECT atanh(0)
} {0.0}

do_execsql_test atanh-float {
  SELECT atanh(-0.5)
} {-0.549306144334055}

do_execsql_test atanh-str {
  SELECT atanh('-0.5')
} {-0.549306144334055}

do_execsql_test atanh-null {
  SELECT atanh(null)
} {}


do_execsql_test ceil-int {
  SELECT ceil(1)
} {1}

do_execsql_test ceil-float {
  SELECT ceil(-1.5)
} {-1.0}

do_execsql_test ceil-str {
  SELECT ceil('1.5')
} {2.0}

do_execsql_test ceil-null {
  SELECT ceil(null)
} {}


do_execsql_test ceiling-int {
  SELECT ceiling(1)
} {1}

do_execsql_test ceiling-float {
  SELECT ceiling(-1.5)
} {-1.0}

do_execsql_test ceiling-str {
  SELECT ceiling('1.5')
} {2.0}

do_execsql_test ceiling-null {
  SELECT ceiling(null)
} {}


do_execsql_test cos-int {
  SELECT cos(1)
} {0.54030230586814}

do_execsql_test cos-float {
  SELECT cos(-0.5)
} {0.877582561890373}

do_execsql_test cos-str {
  SELECT cos('-0.5')
} {0.877582561890373}

do_execsql_test cos-null {
  SELECT cos(null)
} {}


do_execsql_test cosh-int {
  SELECT cosh(1)
} {1.54308063481524}

do_execsql_test cosh-float {
  SELECT cosh(-0.5)
} {1.12762596520638}

do_execsql_test cosh-str {
  SELECT cosh('-0.5')
} {1.12762596520638}

do_execsql_test cosh-null {
  SELECT cosh(null)
} {}


do_execsql_test degrees-int {
  SELECT degrees(1)
} {57.2957795130823}

do_execsql_test degrees-float {
  SELECT degrees(-0.5)
} {-28.6478897565412}

do_execsql_test degrees-str {
  SELECT degrees('-0.5')
} {-28.6478897565412}

do_execsql_test degrees-null {
  SELECT degrees(null)
} {}


do_execsql_test exp-int {
  SELECT exp(1)
} {2.71828182845905}

do_execsql_test exp-float {
  SELECT exp(-0.5)
} {0.606530659712633}

do_execsql_test exp-str {
  SELECT exp('-0.5')
} {0.606530659712633}

do_execsql_test exp-null {
  SELECT exp(null)
} {}


do_execsql_test floor-int {
  SELECT floor(1)
} {1}

do_execsql_test floor-float {
  SELECT floor(-1.5)
} {-2.0}

do_execsql_test floor-str {
  SELECT floor('1.5')
} {1.0}

do_execsql_test floor-null {
  SELECT floor(null)
} {}


do_execsql_test ln-int {
  SELECT ln(1)
} {0.0}

do_execsql_test ln-float {
  SELECT ln(0.5)
} {-0.693147180559945}

do_execsql_test ln-str {
  SELECT ln('0.5')
} {-0.693147180559945}

do_execsql_test ln-negative {
  SELECT ln(-0.5)
} {}

do_execsql_test ln-null {
  SELECT ln(null)
} {}


do_execsql_test log10-int {
  SELECT log10(1)
} {0.0}

do_execsql_test log10-float {
  SELECT log10(0.5)
} {-0.301029995663981}

do_execsql_test log10-str {
  SELECT log10('0.5')
} {-0.301029995663981}

do_execsql_test log10-negative {
  SELECT log10(-0.5)
} {}

do_execsql_test log10-null {
  SELECT log10(null)
} {}


do_execsql_test log2-int {
  SELECT log2(1)
} {0.0}

do_execsql_test log2-float {
  SELECT log2(0.5)
} {-1.0}

do_execsql_test log2-str {
  SELECT log2('0.5')
} {-1.0}

do_execsql_test log2-negative {
  SELECT log2(-0.5)
} {}

do_execsql_test log2-null {
  SELECT log2(null)
} {}


do_execsql_test radians-int {
  SELECT radians(1)
} {0.0174532925199433}

do_execsql_test radians-float {
  SELECT radians(-0.5)
} {-0.00872664625997165}

do_execsql_test radians-str {
  SELECT radians('-0.5')
} {-0.00872664625997165}

do_execsql_test radians-null {
  SELECT radians(null)
} {}


do_execsql_test sinh-int {
  SELECT sinh(1)
} {1.1752011936438}

do_execsql_test sinh-float {
  SELECT sinh(-0.5)
} {-0.521095305493747}

do_execsql_test sinh-str {
  SELECT sinh('-0.5')
} {-0.521095305493747}

do_execsql_test sinh-null {
  SELECT sinh(null)
} {}


do_execsql_test sqrt-int {
  SELECT sqrt(1)
} {1.0}

do_execsql_test sqrt-float {
  SELECT sqrt(0.5)
} {0.707106781186548}

do_execsql_test sqrt-str {
  SELECT sqrt('0.5')
} {0.707106781186548}

do_execsql_test sqrt-negative {
  SELECT sqrt(-0.5)
} {}

do_execsql_test sqrt-null {
  SELECT sqrt(null)
} {}


do_execsql_test tanh-int {
  SELECT tanh(1)
} {0.761594155955765}

do_execsql_test tanh-float {
  SELECT tanh(-0.5)
} {-0.46211715726001}

do_execsql_test tanh-str {
  SELECT tanh('-0.5')
} {-0.46211715726001}

do_execsql_test tanh-null {
  SELECT tanh(null)
} {}


do_execsql_test trunc-int {
  SELECT trunc(1)
} {1}

do_execsql_test trunc-float {
  SELECT trunc(2.5)
} {2.0}

do_execsql_test trunc-float-negative {
  SELECT trunc(-2.5)
} {-2.0}

do_execsql_test trunc-str {
  SELECT trunc('2.5')
} {2.0}

do_execsql_test trunc-null {
  SELECT trunc(null)
} {}


do_execsql_test atan2-int-int {
  SELECT atan2(5, -1)
} {1.76819188664478}

do_execsql_test atan2-int-float {
  SELECT atan2(5, -1.5)
} {1.86225312127276}

do_execsql_test atan2-int-str {
  SELECT atan2(5, '-1.5')
} {1.86225312127276}

do_execsql_test atan2-float-int {
  SELECT atan2(5.5, 10)
} {0.502843210927861}

do_execsql_test atan2-float-float {
  SELECT atan2(5.5, -1.5)
} {1.83704837594582}

do_execsql_test atan2-float-str {
  SELECT atan2(5.5, '-1.5')
} {1.83704837594582}

do_execsql_test atan2-str-str {
  SELECT atan2('5.5', '-1.5')
} {1.83704837594582}

do_execsql_test atan2-null-int {
  SELECT atan2(null, 5)
} {}

do_execsql_test atan2-int-null {
  SELECT atan2(5, null)
} {}


do_execsql_test mod-int-int {
  SELECT mod(10, -3)
} {1.0}

do_execsql_test mod-int-float {
  SELECT mod(5, -1.5)
} {0.5}

do_execsql_test mod-int-str {
  SELECT mod(5, '-1.5')
} {0.5}

do_execsql_test mod-float-int {
  SELECT mod(5.5, 2)
} {1.5}

do_execsql_test mod-float-float {
  SELECT mod(5.5, -1.5)
} {1.0}

do_execsql_test mod-float-str {
  SELECT mod(5.5, '-1.5')
} {1.0}

do_execsql_test mod-str-str {
  SELECT mod('5.5', '-1.5')
} {1.0}

do_execsql_test mod-null-int {
  SELECT mod(null, 5)
} {}

do_execsql_test mod-int-null {
  SELECT mod(5, null)
} {}

do_execsql_test mod-float-zero {
  SELECT mod(1.5, 0)
} {}

do_execsql_test mod-tricky {
  SELECT  mod(atanh(tanh(-1.0)), 1.0)
} {-1.0}

do_execsql_test mod-products-id {
  SELECT mod(products.id, 3) from products limit 5
} {1.0
2.0
0.0
1.0
2.0}

do_execsql_test mod-products-price-id {
  SELECT mod(products.price, products.id) from products limit 5
} {0.0
0.0
0.0
1.0
4.0}


do_execsql_test pow-int-int {
  SELECT pow(5, -1)
} {0.2}

do_execsql_test pow-int-float {
  SELECT pow(5, -1.5)
} {0.0894427190999916}

do_execsql_test pow-int-str {
  SELECT pow(5, '-1.5')
} {0.0894427190999916}

do_execsql_test pow-float-int {
  SELECT pow(5.5, 2)
} {30.25}

do_execsql_test pow-float-float {
  SELECT pow(5.5, -1.5)
} {0.077527533220222}

do_execsql_test pow-float-str {
  SELECT pow(5.5, '-1.5')
} {0.077527533220222}

do_execsql_test pow-str-str {
  SELECT pow('5.5', '-1.5')
} {0.077527533220222}

do_execsql_test pow-null-int {
  SELECT pow(null, 5)
} {}

do_execsql_test pow-int-null {
  SELECT pow(5, null)
} {}


do_execsql_test power-int-int {
  SELECT power(5, -1)
} {0.2}

do_execsql_test power-int-float {
  SELECT power(5, -1.5)
} {0.0894427190999916}

do_execsql_test power-int-str {
  SELECT power(5, '-1.5')
} {0.0894427190999916}

do_execsql_test power-float-int {
  SELECT power(5.5, 2)
} {30.25}

do_execsql_test power-float-float {
  SELECT power(5.5, -1.5)
} {0.077527533220222}

do_execsql_test power-float-str {
  SELECT power(5.5, '-1.5')
} {0.077527533220222}

do_execsql_test power-str-str {
  SELECT power('5.5', '-1.5')
} {0.077527533220222}

do_execsql_test power-null-int {
  SELECT power(null, 5)
} {}

do_execsql_test power-int-null {
  SELECT power(5, null)
} {}


do_execsql_test log-int {
  SELECT log(1)
} {0.0}

do_execsql_test log-float {
  SELECT log(1.5)
} {0.176091259055681}

do_execsql_test log-str {
  SELECT log('1.5')
} {0.176091259055681}

do_execsql_test log-negative {
  SELECT log(-1.5)
} {}

do_execsql_test log-null {
  SELECT log(null)
} {}

do_execsql_test log-int-int {
  SELECT log(5, 1)
} {0.0}

do_execsql_test log-int-float {
  SELECT log(5, 1.5)
} {0.251929636412592}

do_execsql_test log-int-str {
  SELECT log(5, '1.5')
} {0.251929636412592}

do_execsql_test log-float-int {
  SELECT log(5.5, 10)
} {1.35068935021985}

do_execsql_test log-float-float {
  SELECT log(5.5, 1.5)
} {0.237844588273313}

do_execsql_test log-float-str {
  SELECT log(5.5, '1.5')
} {0.237844588273313}

do_execsql_test log-str-str {
  SELECT log('5.5', '1.5')
} {0.237844588273313}

do_execsql_test log-negative-negative {
  SELECT log(-1.5, -1.5)
} {}

do_execsql_test log-float-negative {
  SELECT log(1.5, -1.5)
} {}

do_execsql_test log-null-int {
  SELECT log(null, 5)
} {}

do_execsql_test log-int-null {
  SELECT log(5, null)
} {}

do_execsql_test remainder-int-null {
  SELECT 183 % null
} {}

do_execsql_test remainder-int-0 {
  SELECT 183 % 0
} {}

do_execsql_test remainder-int-int {
  SELECT 183 % 10
} { 3 }

do_execsql_test remainder-int-float {
  SELECT 38 % 10.35
} { 8.0 }

do_execsql_test remainder-float-int {
  SELECT 38.43 % 13
} { 12.0 }

do_execsql_test remainder-0-float {
  SELECT 0 % 12.0
} { 0.0 }

do_execsql_test remainder-float-0 {
  SELECT 23.14 % 0
} {}

do_execsql_test remainder-float-float {
  SELECT 23.14 % 12.0
} { 11.0 }

do_execsql_test remainder-float-agg {
    SELECT 23.14 % sum(id) from products
} { 23.0 }

do_execsql_test remainder-int-agg {
    SELECT 17 % sum(id) from users
} { 17 }

do_execsql_test remainder-agg-int {
    SELECT count(*) % 17 from users
} { 4 }

do_execsql_test remainder-agg-float {
    SELECT count(*) % 2.43 from users
} { 0.0 }

foreach {testnum lhs rhs ans} {
   1   'a'    'a'   {}
   2   'a'    10    0
   3   10     'a'   {}
   4   'a'    11.0  0.0
   5   11.0   'a'   {}
   7   '10'   '3'   1
   8   '10.0' '3'   1.0
   9   '10.0' -3    1.0
} {
  do_execsql_test remainder-text-$testnum "SELECT $lhs % $rhs" $::ans
}

foreach {testnum lhs rhs ans} {
   1   '-9223372036854775808'  '-1'  0 
   2   -9223372036854775808     -1   0
   3   -9223372036854775809     -1   0.0
} {
  do_execsql_test remainder-overflow-$testnum "SELECT $lhs % $rhs" $::ans
}

do_execsql_test comp-float-float {
    SELECT 0.0 = 0.0
} { 1 }

do_execsql_test comp-int-float {
    SELECT 0 = 0.0
} { 1 }

do_execsql_test comp-float-int {
    SELECT 0.0 = 0
} { 1 }

do_execsql_test comp-int-string {
    SELECT 0 = '0'
} { 0 }

do_execsql_test comp-string-int {
    SELECT '0' = 0
} { 0 }

do_execsql_test comp-string-blog {
    SELECT '0' = cast('0' as BLOB)
} { 0 }

do_execsql_test comp-blog-string {
    SELECT cast('0' as BLOB) = '0'
} { 0 }

do_execsql_test comp-blog-blog {
    SELECT cast('0' as BLOB) = cast('0' as BLOB)
} { 1 }

do_execsql_test unary-plus-noop-string {
    SELECT +'000'
} { 000 }

do_execsql_test unary-plus-noop-blob {
    SELECT typeof(+x'00') = 'blob'
} { 1 }

do_execsql_test_on_specific_db {:memory:} is-nonnull-divide-by-zero {
    CREATE TABLE t (x PRIMARY KEY, y, z);
    INSERT INTO t VALUES (37, -70, -196792117);
    SELECT * FROM t WHERE  (1 / 0) >= -3289742039 < t.x;
} {}
